summaryrefslogtreecommitdiffhomepage
path: root/packages/enterprise/src/routes/api/[...path].ts
diff options
context:
space:
mode:
authorDax <[email protected]>2025-11-21 20:41:27 -0500
committerGitHub <[email protected]>2025-11-21 20:41:27 -0500
commit49408c00e964093c654ee270d545c0e29857e61f (patch)
tree600b2a94cd082c0af221fd84fd5346cfe8f9ace4 /packages/enterprise/src/routes/api/[...path].ts
parent76192fbcedff945b5d529a5d733deb2488ee9c8a (diff)
downloadopencode-49408c00e964093c654ee270d545c0e29857e61f.tar.gz
opencode-49408c00e964093c654ee270d545c0e29857e61f.zip
enterprise (#4617)
Co-authored-by: GitHub Action <[email protected]> Co-authored-by: Adam <[email protected]>
Diffstat (limited to 'packages/enterprise/src/routes/api/[...path].ts')
-rw-r--r--packages/enterprise/src/routes/api/[...path].ts152
1 files changed, 152 insertions, 0 deletions
diff --git a/packages/enterprise/src/routes/api/[...path].ts b/packages/enterprise/src/routes/api/[...path].ts
new file mode 100644
index 000000000..bbca171bd
--- /dev/null
+++ b/packages/enterprise/src/routes/api/[...path].ts
@@ -0,0 +1,152 @@
+import type { APIEvent } from "@solidjs/start/server"
+import { Hono } from "hono"
+import { describeRoute, openAPIRouteHandler, resolver } from "hono-openapi"
+import { validator } from "hono-openapi"
+import z from "zod"
+import { cors } from "hono/cors"
+import { Share } from "~/core/share"
+
+const app = new Hono()
+
+app
+ .basePath("/api")
+ .use(cors())
+ .get(
+ "/doc",
+ openAPIRouteHandler(app, {
+ documentation: {
+ info: {
+ title: "Opencode Enterprise API",
+ version: "1.0.0",
+ description: "Opencode Enterprise API endpoints",
+ },
+ openapi: "3.1.1",
+ },
+ }),
+ )
+ .post(
+ "/share",
+ describeRoute({
+ description: "Create a share",
+ operationId: "share.create",
+ responses: {
+ 200: {
+ description: "Success",
+ content: {
+ "application/json": {
+ schema: resolver(
+ z
+ .object({
+ url: z.string(),
+ secret: z.string(),
+ })
+ .meta({ ref: "Share" }),
+ ),
+ },
+ },
+ },
+ },
+ }),
+ validator("json", z.object({ sessionID: z.string() })),
+ async (c) => {
+ const body = c.req.valid("json")
+ const share = await Share.create({ id: body.sessionID })
+ const protocol = c.req.header("x-forwarded-proto") ?? c.req.header("x-forwarded-protocol") ?? "https"
+ const host = c.req.header("x-forwarded-host") ?? c.req.header("host")
+ return c.json({
+ secret: share.secret,
+ url: `${protocol}://${host}/share/${share.id}`,
+ })
+ },
+ )
+ .post(
+ "/share/:sessionID/sync",
+ describeRoute({
+ description: "Sync share data",
+ operationId: "share.sync",
+ responses: {
+ 200: {
+ description: "Success",
+ content: {
+ "application/json": {
+ schema: resolver(z.object({})),
+ },
+ },
+ },
+ },
+ }),
+ validator("param", z.object({ sessionID: z.string() })),
+ validator("json", z.object({ secret: z.string(), data: Share.Data.array() })),
+ async (c) => {
+ const { sessionID } = c.req.valid("param")
+ const body = c.req.valid("json")
+ await Share.sync({
+ share: { id: sessionID, secret: body.secret },
+ data: body.data,
+ })
+ return c.json({})
+ },
+ )
+ .get(
+ "/share/:sessionID/data",
+ describeRoute({
+ description: "Get share data",
+ operationId: "share.data",
+ responses: {
+ 200: {
+ description: "Success",
+ content: {
+ "application/json": {
+ schema: resolver(z.array(Share.Data)),
+ },
+ },
+ },
+ },
+ }),
+ validator("param", z.object({ sessionID: z.string() })),
+ async (c) => {
+ const { sessionID } = c.req.valid("param")
+ return c.json(await Share.data(sessionID))
+ },
+ )
+ .delete(
+ "/share/:sessionID",
+ describeRoute({
+ description: "Remove a share",
+ operationId: "share.remove",
+ responses: {
+ 200: {
+ description: "Success",
+ content: {
+ "application/json": {
+ schema: resolver(z.object({})),
+ },
+ },
+ },
+ },
+ }),
+ validator("param", z.object({ sessionID: z.string() })),
+ validator("json", z.object({ secret: z.string() })),
+ async (c) => {
+ const { sessionID } = c.req.valid("param")
+ const body = c.req.valid("json")
+ await Share.remove({ id: sessionID, secret: body.secret })
+ return c.json({})
+ },
+ )
+
+export function GET(event: APIEvent) {
+ return app.fetch(event.request)
+}
+
+export function POST(event: APIEvent) {
+ return app.fetch(event.request)
+}
+
+export function PUT(event: APIEvent) {
+ return app.fetch(event.request)
+}
+
+export async function DELETE(event: APIEvent) {
+ return app.fetch(event.request)
+}